package com.songlanyun.modules.marketing.seckill.model.vo;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.drive.ValueObject;
import com.songlanyun.common.enums.MarketingConstant;
import com.songlanyun.common.enums.OrderConstant;
import com.songlanyun.common.utils.DateUtils;
import com.songlanyun.common.utils.SpringContextUtils;
import com.songlanyun.common.utils.custom.DateCustomUtils;
import com.songlanyun.common.utils.custom.MathUtils;
import com.songlanyun.modules.marketing.seckill.entity.SeckillGoodsSku;
import com.songlanyun.modules.marketing.seckill.service.SeckillActivityGoodsService;
import com.songlanyun.modules.marketing.seckill.service.SeckillActivityService;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * 秒杀活动商品表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 17:30:11
 */
@Data
public class SeckillActivityGoodsVO implements ValueObject {


    /**
     * 秒杀商品id
     */
    private Long id;

    //========商品=======
    /**
     * 商品id
     */
    private Long shopId;
    /**
     * 商品id
     */
    private Long goodsId;
    /**
     * 商品名称
     */
    private String title;
    /**
     * 商品图片
     */
    private String cover;
    /**
     * 最低售价
     */
    private BigDecimal minSalePrice;
    /**
     * 最高售价
     */
    private BigDecimal maxSalePrice;
    /**
     * 主图视频
     */
    private String videoUrl;
    /**
     * 短标题
     */
    private String shortTitle;
    /**
     * 商品详情
     */
    private String mobileDetail;
    //========商品=======

    /**
     * 秒杀活动id
     */
    private Long seckillId;
    /**
     * 0固定折扣,1固定减价
     */
    private MarketingConstant.PriceType priceType;
    /**
     * 固定折扣、
     */
    private BigDecimal discount;

    /**
     * 最低售价
     */
    private BigDecimal consumptionValue;

    public BigDecimal loadDiscount() {

        if (this.priceType.equals(MarketingConstant.PriceType.PRICE_FIXED_BY)) {
            this.discount = MathUtils.multiplyMulti(1, MathUtils.divideMulti(2, this.getMinPrice(), this.getMinSalePrice()),
                    new BigDecimal(10));
        }

        return this.discount;
    }

    /**
     * 固定减多少钱
     */
    private BigDecimal fixPrice;

    /**
     * 活动价格区间
     */
    private String discountSection;

    public String getDiscountSection() {
        return this.minPrice + " - " + this.maxPrice;
    }

    /**
     * 限购
     */
    private Integer limitBuyNum;
    /**
     *
     */
    private BigDecimal minPrice;
    /**
     *
     */
    private BigDecimal maxPrice;
    /**
     * 活动价
     */
    private BigDecimal activityPrice;
    /**
     * 销售价
     */
    private BigDecimal salePrice;
    /**
     * 投放的真实库存总数
     */
    private Integer realStockTotal;
    /**
     * 初始化销量（假销量）
     */
    private Integer initSaleNum;
    /**
     * 真实销量
     */
    private Integer realSaleNum;
    /**
     * 输出销量(初始化销量+真实销量)
     */
    private Integer resultSaleNum;

    /**
     * 剩余库存(real_stock_total-result_sale_num)
     */
    private Integer residueStockTotal;
    /**
     * 商品排序
     */
    private Integer sort;

    /**
     * 是推荐商品
     */
    private Boolean recommended;

    /**
     * 场次的开始小时数（9:00）
     */
    private String startHour;
    /**
     * 场次的结束小时数（12:00）
     */
    private String endHour;
    /**
     * 活动开始时间
     */
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date startTime;

    /**
     * 活动结束时间
     */
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date endTime;

    private Long activityStartTime;//活动开始时间

    public Long getActivityStartTime() {
        Date date = new Date();
        if (this.getStartTime().getTime() <= System.currentTimeMillis()
                && System.currentTimeMillis() <= DateUtils.addDateDays(this.getEndTime(), 1).getTime()) {
            date = DateUtils.stringToDate(DateCustomUtils.dateToString(new Date()) + " " + this.getStartHour());
        } else {
            date = DateUtils.stringToDate(DateCustomUtils.dateToString(this.getStartTime()) + " " + this.getStartHour());
        }
        return date.getTime() / 1000;
    }

    public Long getWillStartTime() {
        Date date = new Date();
        if (this.getStartTime().getTime() <= System.currentTimeMillis()
                && System.currentTimeMillis() <= DateUtils.addDateDays(this.getEndTime(), 1).getTime()) {
            date = DateUtils.stringToDate(DateCustomUtils.dateToString(DateUtils.addDateDays(new Date(), 1)) + " " + this.getStartHour());
        } else {
            date = DateUtils.stringToDate(DateCustomUtils.dateToString(this.getStartTime()) + " " + this.getStartHour());
        }
        return date.getTime() / 1000;
    }

    private Long finishTime;//结束时间

    public Long getFinishTime() {
        Date date = DateUtils.stringToDate(DateCustomUtils.dateToString(new Date()) + " " + this.getEndHour());
        this.finishTime = date.getTime();
        return date.getTime() / 1000;
    }

    /**
     * 活动状态
     */
    private MarketingConstant.ActiveState activeState;

    /**
     * 已抢百分比
     */
    private Integer rate;

    /**
     * 活动状态
     *
     * @return
     */
    public MarketingConstant.ActiveState getActiveState() {

        return MarketingConstant.getSeckillActiveState(this.startTime, this.endTime, this.startHour, this.endHour);

    }

    /**
     * 秒杀商品规格
     */
//    private List<SeckillGoodsSku> seckillGoodsSkus;

}
